#include <iostream>
#include <queue>
using namespace std;

const int N = 1e7 + 5;
int n, ans, ep, door = 1;
int depth[N];
bool vis[N];

struct EDGE
{
    int s, e;
    EDGE* next;
} edges[N];

struct NODE
{
    EDGE* first;
} nodes[N];

void addedges(int a, int b)
{
    edges[ep] = { a, b, nodes[a].first };
    nodes[a].first = &edges[ep];
    ep++;
}

void bfs(int start)
{
    queue<NODE> qu;
    qu.push(nodes[start]);
    depth[start] = 1;
    while (!qu.empty())
    {
        NODE node = qu.front();
        qu.pop();
        EDGE* e = node.first;
        while (e != NULL)
        {
            depth[e->e] = depth[e->s] + 1;
            if (ans < depth[e->e])
            {
                door = e->e;
            }
            qu.push(nodes[e->e]);
            e = e->next;
        }
    }
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int cnt;
        cin >> cnt;
        while (cnt--)
        {
            int val;
            cin >> val;
            vis[val] = true;
            addedges(i, val);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (!vis[i])
        {
            bfs(i);
            break;
        }
    }
    cout << door;
    return 0;
}